package com.whjz.dcfs.ggts.struts.action;

import java.text.DecimalFormat;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.whjz.dcfs.ggts.dao.IDcfsTsclTsjcsjJbxxDAO;
import com.whjz.dcfs.ggts.model.DcfsTsclTsjcsjJbxx;
import com.whjz.dcfs.jzxx.dao.IDcfsJzSbJbxxDAO;
import com.whjz.dcfs.jzxx.model.DcfsJzSbJbxx;
import com.whjz.dcfs.util.BaseAction;

public class JZTSSJAction extends BaseAction{

	private static final long serialVersionUID = 1L;

	private DcfsTsclTsjcsjJbxx dcfsTsclTsjcsjJbxx;
	@Autowired
	public IDcfsJzSbJbxxDAO dcfsJzSbJbxxDAO;
	
	private DcfsJzSbJbxx dcfsJzSbJbxx;
	@Autowired
	private IDcfsTsclTsjcsjJbxxDAO dcfsTsclTsjcsjJbxxDAO;
	
	public void insertDcfsTsclTsjcsjJbxx() throws Exception{
		try{
			DcfsJzSbJbxx ds=dcfsJzSbJbxxDAO.getDcfsJzSbJbxxByPK(dcfsJzSbJbxx);
			Double dBi=Double.valueOf(ds.getJztxzy()==null?"15":ds.getJztxzy());//天线增益
			Double a= Double.valueOf(dcfsTsclTsjcsjJbxx.getJcdxdjlsp());
			Double b= Double.valueOf(dcfsTsclTsjcsjJbxx.getJcdxdjlcz());
			Double DP= Double.valueOf(dcfsTsclTsjcsjJbxx.getJcdglshgl());//损耗值
			Double P1= Double.valueOf(ds.getJzbcgl()==null?"20":ds.getJzbcgl());//标称功率
			Double dBd=dBi-2.15;
			double G = Math.pow(10,dBd/10.00);
			double P2=Math.log10(P1)*10+30;
			double P = Math.pow(10,(P2-DP)/10.00);
			double APd=(P*G/(4*Math.PI*(a*a+b*b)))*100;
			double CPd=APd*0.8;
			DecimalFormat df = new DecimalFormat("0.##");
			dcfsTsclTsjcsjJbxx.setApdvalue(df.format(APd));
			dcfsTsclTsjcsjJbxx.setCpdvalue(df.format(CPd));
			dcfsTsclTsjcsjJbxxDAO.insertDcfsTsclTsjcsjJbxx(dcfsTsclTsjcsjJbxx);
			getHttpServletResponse().getWriter().println("{success:'true',msg:'添加成功'}");
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	public void deleteDcfsTsclTsjcsjJbxxByCond() throws Exception{
		try{
			dcfsTsclTsjcsjJbxxDAO.deleteDcfsTsclTsjcsjJbxxByCond(dcfsTsclTsjcsjJbxx);
			getHttpServletResponse().getWriter().println("{success:'true',msg:'删除成功'}");
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	public void getDcfsTsclTsjcsjJbxxListByCond() throws Exception{
		try{
			getHttpServletResponse().setCharacterEncoding("utf-8");
			List<DcfsTsclTsjcsjJbxx> list=dcfsTsclTsjcsjJbxxDAO.getDcfsTsclTsjcsjJbxxListByCond(dcfsTsclTsjcsjJbxx);
			StringBuffer sb=new StringBuffer();
			sb.append("{DCFS_GBDS_SB_JBXX:[");
			if(list!=null&&list.size()>0){
				for (int i = 0; i < list.size(); i++) {
					sb.append("{");
					sb.append("TS_BH:'"+(list.get(i).getTsbh()==null?"":list.get(i).getTsbh())+"',");
					sb.append("JCD_BM:'"+(list.get(i).getJcdbm()==null?"":list.get(i).getJcdbm())+"',");
					sb.append("JCD_MC:'"+(list.get(i).getJcdmc()==null?"":list.get(i).getJcdmc())+"',");
					sb.append("JCD_XDFW:'"+(list.get(i).getJcdxdfw()==null?"":list.get(i).getJcdxdfw())+"',");
					sb.append("JCD_XDJL_SP:'"+(list.get(i).getJcdxdjlsp()==null?"":list.get(i).getJcdxdjlsp())+"',");
					sb.append("JCD_XDJL_CZ:'"+(list.get(i).getJcdxdjlcz()==null?"":list.get(i).getJcdxdjlcz())+"',");
					sb.append("JCD_GLSH_GL:'"+(list.get(i).getJcdglshgl()==null?"":list.get(i).getJcdglshgl())+"',");
					sb.append("Avalue:'"+(list.get(i).getApdvalue()==null?"":list.get(i).getApdvalue())+"',");
					sb.append("CValue:'"+(list.get(i).getCpdvalue()==null?"":list.get(i).getCpdvalue())+"'");
					sb.append("}");
					if(i < list.size()-1){
						sb.append(",");
					}
				}
			}
			sb.append("]}");
//			System.out.println("----------------------------"+sb);
			getHttpServletResponse().getWriter().println(sb);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	public DcfsTsclTsjcsjJbxx getDcfsTsclTsjcsjJbxx() {
		return dcfsTsclTsjcsjJbxx;
	}
	public void setDcfsTsclTsjcsjJbxx(DcfsTsclTsjcsjJbxx dcfsTsclTsjcsjJbxx) {
		this.dcfsTsclTsjcsjJbxx = dcfsTsclTsjcsjJbxx;
	}

	public DcfsJzSbJbxx getDcfsJzSbJbxx() {
		return dcfsJzSbJbxx;
	}

	public void setDcfsJzSbJbxx(DcfsJzSbJbxx dcfsJzSbJbxx) {
		this.dcfsJzSbJbxx = dcfsJzSbJbxx;
	}
	
	
}
